<?php
switch($cf_action){
	case "index":
		if($cf_user_info){
				header("location:http://www.d2ziran.com/user/index.htm");
				exit;
				//my_jump('你已在登录中,请不要重复登录了');	
			}
		if($cf_ispost){			
			$name = trim($_POST['user_name']);			
			$pwd = trim($_POST['pwd']);	
			if($name && $pwd){
				load_file('valid_class', LIB_PATH);
				$valid = new Valid($db);			
				if (!$valid->email($name)) {
					my_jump('登陆账号必须是邮箱!');
				}		
				$cf_user_info =$userauth->login($name,$pwd);		
				if($cf_user_info){
					
					if($cf_user_info['user_status']=='0'){
						my_jump('您已被限制登录!<br>原因:'.$cf_user_info['user_close_reason']);						
					}					
					$return_page = $_SESSION['my_jump'] ? $_SESSION['my_jump'] :  "/user/index.htm";			
					if($return_page){	
						//setcookie("url","");					
						header("location:".$return_page);
					}else{						
						header("location:/user/index.htm");				
					}
				}else{
					my_jump('输入的用户名与密码不正确');
				}			
				exit;
			}else{
				my_jump('输入的用户名与密码不能为空');
			}
		}		
		
		$_SESSION['my_jump'] = $cf_pre_page;
		
	break;
	case "reg":
		if($cf_ispost){
			load_file('valid_class', LIB_PATH);
			$valid = new Valid($db);
		/*	$code = strtoupper(trim($_POST['code']));
			if ($code != $_SESSION['verifycode']) {
				my_jump('验证码输入错误!');
			}*/
			
			$reg_name = trim($_POST['reg_name']);//用户名是邮箱的格式
			if (!$valid->email($reg_name)) {
				my_jump('无效的邮箱!');
			}	
			
			load_file('user_class', LIB_PATH);
			$main = new User($db);
			$rs = $main->search_user($reg_name);
			if ($rs) {
				my_jump('此邮箱已被注册');
			}
			
			$pwd = md5(trim($_POST['reg_pwd']));
			$data['user_name'] = $reg_name;
			$data['user_pwd'] = $pwd;
			$data['user_email'] = $reg_name;
			$data['user_reg_time'] = date("Y-m-d H:i:s");
			$data['user_reg_ip'] = get_ip();			
			$user_id = $main->insert_data($data);
			if($user_id){		
				$user_info = $userauth->login($reg_name,trim($_POST['reg_pwd']));					
				$return_page = $_SESSION['my_jump'] ? $_SESSION['my_jump'] :  "/user/index.htm";
				my_jump('注册成功!', '', $return_page, 3);
			}else{
				my_jump('注册失败!');
			}		
			
		}
			
		$_SESSION['my_jump'] = $cf_pre_page;	
		
		
	break;
	case "logout":
		$userauth->logout();
		header("location:/default/index.htm");
		exit;
	break;
	default:
	my_jump('非法操作!');
	break;
	
}

$smarty->mypage($cf_controller,$cf_action,0);

$smarty->assign(array(

));
$smarty->mydisplay();
?>